package com.example.common.reader.upload;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;


public class TCPFileUploadServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(6666);
        System.out.println("服务端再在6666端口监听.....");
        Socket socket = serverSocket.accept();

        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        byte[] bytes = StreamUtils.streamToByteArray(bis);
        String destFilePath = "C:\\Users\\Mr.Liu\\Desktop\\codeT\\teaching\\javaEE\\src\\风景2.jpg";
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFilePath));
        bos.write(bytes);
        bos.close();

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("收到图片");
        bw.flush();
        socket.shutdownOutput();

        bis.close();
        socket.close();
        serverSocket.close();
    }
}
